package com.yy.wga.admin.service.controller;


import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.yy.wga.mp.common.interceptor.RequestUserHolder;
import com.yy.wga.mp.module.admin.request.AdminMerchantMomentSharePageRequest;
import com.yy.wga.mp.module.admin.request.AdminMerchantMomentShareSaveRequest;
import com.yy.wga.mp.module.admin.request.AdminMerchantMomentShareUpdateStatusRequest;
import com.yy.wga.mp.module.admin.response.AdminMerchantMomentSharePageResponse;
import com.yy.wga.mp.module.merchant.entity.pojo.MerchantMomentShareDO;
import com.yy.wga.mp.module.merchant.service.MerchantMomentShareService;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 运营后台/发圈素材配置
 *
 * @author guochao
 * @since 2024-10-31 22:12:53
 */
@RestController
@RequestMapping("admin/resource/momentShare")
public class AdminResourceMomentShareController {
    /**
     * 服务对象
     */
    @Resource
    private MerchantMomentShareService merchantMomentShareService;

    @PostMapping("page")
    public Result<PageBean<AdminMerchantMomentSharePageResponse>> page(@Valid @RequestBody AdminMerchantMomentSharePageRequest request) {
        PageBean<AdminMerchantMomentSharePageResponse> pageBean = merchantMomentShareService.pageData(request);
        return Result.success(pageBean);
    }

    @PostMapping("save")
    public Result<Boolean> save(@Valid @RequestBody AdminMerchantMomentShareSaveRequest request) {
        merchantMomentShareService.saveData(request);
        return Result.success(Boolean.TRUE);
    }

    @PostMapping("updateShareInfo")
    public Result<Boolean> updateShareInfo(@Valid @RequestBody AdminMerchantMomentShareUpdateStatusRequest request) {
        merchantMomentShareService.update(new LambdaUpdateWrapper<MerchantMomentShareDO>()
                .eq(MerchantMomentShareDO::getAppKey, RequestUserHolder.getBaseRequest().getAppKey())
                .eq(MerchantMomentShareDO::getId, request.getId())
                .set(request.getSort() != null, MerchantMomentShareDO::getSort, request.getSort())
                .set(request.getStatus() != null, MerchantMomentShareDO::getStatus, request.getStatus())
                .set(request.getTop() != null, MerchantMomentShareDO::getTop, request.getTop()));
        return Result.success(Boolean.TRUE);
    }

    @GetMapping("del")
    public Result<Boolean> del(@RequestParam("id") Long id) {
        merchantMomentShareService.removeById(id);
        return Result.success(Boolean.TRUE);
    }
}
